// pages/seat_lib/seat_detail_stu/seat_detail_stu.js
var date = new Date();
var currentHours = date.getHours();
var currentMinute = date.getMinutes();
const baseURL = 'http://100.2.178.56:8080'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentHour_: 0,
        startDate: "开始时间",
        startDay: null,
        startTime: null,
        startMinute: null,
        startDate1: "结束时间",
        endTime: null,
        endMinute: null,

        resStarHour: 0,
        resStarMinu: 0,
        resEndHour: 0,
        resEndMinu: 0,
        seatDetail: null,
        // .js
        multiArray: [

            [0, 1, 2, 3, 4, 5, 6],
            [0, 10, 20]
        ],
        multiIndex: [0, 0],
        multiArray1: [

            [0, 1, 2, 3, 4, 5, 6],
            [0, 10, 20]
        ],
        multiIndex1: [0, 0, 0],
        reserve: null,
        todayReserve_over: false,
        tomorrow: false,
        theResTime: [],
        currNew: currentHours,
        currNew_end: currentHours,
        endHour_end: currentHours
    },
    reserve_click: function () {

        //1、验证是否预约时间，时间间隔应有一个小时起步
        var that = this
        var check = this.data.endTime - this.data.startTime
        if ((check == 1 && this.data.endMinute >= this.data.startMinute) || (check > 1)) {

            //调整预约时间格式
            //1、先判断是今天还是明天
            var datee = new Date();
            var starttime;
            var endtime
            if (this.data.seatDetail.tomorrow) {
                //明天
                var date1 = new Date(datee);
                date1.setDate(date.getDate() + 1);

                var monthDay = this.convertMonthDay(date1.getMonth() + 1, date1.getDate())
                starttime = date.getFullYear() + "年" + monthDay + ' ' + that.data.startDate;
                endtime = date.getFullYear() + "年" + monthDay + ' ' + that.data.startDate1
                console.log("monthDay=>starttime:", starttime)

            } else {
                //今天
                var month = datee.getMonth() + 1;
                var day = datee.getDate();
                monthDay = this.convertMonthDay(month, day);
                starttime = date.getFullYear() + "年" + monthDay + ' ' + that.data.startDate;
                endtime = date.getFullYear() + "年" + monthDay + ' ' + that.data.startDate1
            }


            //2、第二步查看本人有没有诚信违反
            wx.request({
                url: baseURL + '/honestStudent/id',
                method: 'GET',
                header: {
                    'Authorization': getApp().token
                },
                success: function (res) {
                    if (res.data.code == 0) {
                        wx.request({
                            url: baseURL + '/studentSeatRelation/reserve',
                            header: {
                                'Authorization': getApp().token
                            },
                            data: {
                                // "seaId": that.data.seatDetail.seat.seaId,
                                "seaStaId": that.data.seatDetail.seaStaId,
                                "stuId": getApp().globalUserInfo.stuId,
                                "resTimeId": that.data.seatDetail.reserveTime.resTimeId,
                                "startTime": starttime,
                                "endTime": endtime
                            },
                            success: function (res) {
                                if (res.data.code == 0) {
                                    wx.showToast({
                                            title: '预约成功！！！' + '请在' + that.data.startDate + '之前到达，扫座位前的二维码完成签到',
                                            icon: 'none',
                                            duration: 3000
                                        }),

                                        //预约完成，需要重新加载页面
                                        getApp().user_reserve = res.data.data.reserve
                                    getApp().seaNum = that.data.seatDetail.seat.seaNum
                                    getApp().floNum = that.data.seatDetail.floNum
                                    setTimeout(function () {
                                        wx.navigateBack({
                                            //   delta: 0,
                                            url: '/pages/seat_lib/seat_lib'
                                        })
                                    }, 1500)


                                } else {
                                    wx.showToast({
                                        title: res.data.message,
                                        icon: 'error',
                                        duration: 2000
                                    })
                                }
                            }
                        })
                    } else {

                        wx.showModal({
                            title: "温馨提示", // 提示的标题
                            content: res.data.message, // 提示的内容
                            showCancel: false, // 是否显示取消按钮，默认true
                            // cancelText: "取消", // 取消按钮的文字，最多4个字符
                            cancelColor: "#000000", // 取消按钮的文字颜色，必须是16进制格式的颜色字符串
                            confirmText: "确定", // 确认按钮的文字，最多4个字符
                            confirmColor: "#576B95", // 确认按钮的文字颜色，必须是 16 进制格式的颜色字符串
                            success: function (res) {
                                if (res.confirm) {}
                            },

                        })
                    }
                }
            })
        } else {
            wx.showToast({
                title: '预约时长要求一个小时起步',
                icon: 'none',
                duration: 3000
            })
        }
    },
    /**
     * 结束时间
     */ // mark: 结束时间
    pickerTap1: function () {
        date = new Date();
        // var monthDay = [this.data.endDay];
        var hours = [];
        var minute = [];

        var data = {
            multiArray1: this.data.multiArray1,
            multiIndex1: this.data.multiIndex1
        };

        console.log("结束时间=>startMinute：", this.data.startMinute)
        //做一个结束时间：如果有下一次预约开始就给出下一次时间开始的前十分钟

        if (data.multiIndex1[0] === 0) {

            //给出一个endHour
            this.loadData_end(hours, minute, this.data.startTime, this.data.startMinute);

        } else {
            console.log("pickerTap1=>loadMinute：：")
            this.loadMinute_end(hours, minute, this.data.startTime, 0);
        }

        data.multiArray1[0] = hours;
        data.multiArray1[1] = minute;

        this.setData(data);
    },


    bindMultiPickerColumnChange1: function (e) {
        date = new Date();

        var that = this;

        // var monthDay = [this.data.endDay];
        var hours = [];
        var minute = [];

        currentHours = date.getHours();
        currentMinute = date.getMinutes();

        var data = {
            multiArray1: this.data.multiArray1,
            multiIndex1: this.data.multiIndex1
        };
        // 把选择的对应值赋值给 multiIndex
        data.multiIndex1[e.detail.column] = e.detail.value;

        if (e.detail.column === 0) {

            if (e.detail.value === 0) {

                //给出一个endHour
                this.loadData_end(hours, minute, this.data.startTime, this.data.startMinute);
            } else {
                console.log("bindMultiPickerColumnChange1=>loadMinute 1")
                this.loadMinute_end(hours, minute, this.data.startTime, e.detail.value);
            }

            data.multiIndex1[1] = 0;
            // 如果是第3列改变
        } else {

            // 如果第一列为 '今天'并且第二列为当前时间
            if (e.detail.value === 0) {

                //给出一个endHour
                this.loadData_end(hours, minute, this.data.startTime, this.data.startMinute);
            } else {
                console.log("bindMultiPickerColumnChange1=>loadMinute 2")
                this.loadMinute_end(hours, minute, this.data.startTime, data.multiIndex1[0]);
            }
        }

        data.multiArray1[0] = hours;
        data.multiArray1[1] = minute;
        this.setData(data);
    },
    bindStartMultiPickerChange1: function (e) {
        var that = this;
        // var monthDay = that.data.multiArray1[0][e.detail.value[0]];
        var hours = that.data.multiArray1[0][e.detail.value[0]];
        var minute = that.data.multiArray1[1][e.detail.value[1]];

        var startDate1 = null;
        if (minute === 0) {
            minute = '0' + minute
        }

        if (this.data.startDate === '开始时间') {

            wx.showToast({
                title: '请先选择开始时间',
                icon: 'none',
                duration: 3000
            })
            startDate1 = '00' + ":" + '00';
        } else {

            if (parseInt(hours) < 10) {
                hours = '0' + hours;
                console.log("hours:", hours)
            }

            startDate1 = hours + ":" + minute;
        }
        that.setData({
            startDate1: startDate1,
            endTime: hours,
            endMinute: minute
        })
    },
    /**
     * 有预约情况开始时间
     */
    pickerTap_res: function () {
        date = new Date();

        var hours = this.data.theResTime
        var minute = [];

        currentHours = date.getHours();
        currentMinute = date.getMinutes();

        var data = {
            multiArray: this.data.multiArray,
            multiIndex: this.data.multiIndex
        };

        if (!this.data.seatDetail.tomorrow) {
            //今天
            // if (data.multiIndex[0] === 0) {
            var currNew = this.loadData_start(hours, minute)
            this.setData({
                currNew: currNew
            })
            // } else {
            // this.loadMinute_start(hours, minute, this.data.currNew, 0);
            // }
        } else {
            //明天
            // this.loadHoursMinute_start(hours, minute, this.data.seatDetail.reserveTime.timeStartTime, this.data.seatDetail.reserveTime.timeEndTime - 1);
        }

        data.multiArray[0] = hours;
        data.multiArray[1] = minute;

        this.setData(data);
    },

    /**
     * 开始时间
     */ // mark:开始时间
    pickerTap: function () {
        date = new Date();

        var hours = [];
        var minute = [];

        currentHours = date.getHours();
        currentMinute = date.getMinutes();

        if (currentHours < this.data.seatDetail.reserveTime.timeStartTime) {
            currentHours = this.data.seatDetail.reserveTime.timeStartTime
        }

        var data = {
            multiArray: this.data.multiArray,
            multiIndex: this.data.multiIndex
        };

        if (!this.data.seatDetail.tomorrow) {
            if (data.multiIndex[0] === 0) {
                var currNew = this.loadData_start(hours, minute, currentHours)
                this.setData({
                    currNew: currNew
                })
            } else {
                console.log("pickerTap=>else")
                this.loadMinute_start(hours, minute, this.data.currNew);
            }

        } else {
            //明天
            var currNew = this.loadData_start_tomorrow(hours, minute)
            this.setData({
                currNew: currNew
            })
        }

        data.multiArray[0] = hours;
        data.multiArray[1] = minute;

        this.setData(data);
    },


    bindMultiPickerColumnChange: function (e) {
        date = new Date();
        console.log("bindMultiPickerColumnChange")
        var that = this;

        // var monthDay = ['今天','明天'];
        var hours = [];
        var minute = [];

        currentHours = date.getHours();
        currentMinute = date.getMinutes();

        if (currentHours < this.data.seatDetail.reserveTime.timeStartTime) {
            currentHours = this.data.seatDetail.reserveTime.timeStartTime
        }
        // if(this.getMinuteByResHour(currentHours))

        var data = {
            multiArray: this.data.multiArray,
            multiIndex: this.data.multiIndex
        };
        // 把选择的对应值赋值给 multiIndex
        data.multiIndex[e.detail.column] = e.detail.value;

        if (e.detail.column === 0) {
            // 如果第一列为今天
            var currNew;
            if (!this.data.seatDetail.tomorrow) {
                if (e.detail.value === 0) {
                    console.log("loadData_start===")
                    currNew = that.loadData_start(hours, minute, currentHours);
                    this.setData({
                        currNew: currNew
                    })
                } else {
                    console.log("loadMinute_start=== e.detail.value:", e.detail.value)
                    that.loadMinute_start(hours, minute, that.data.currNew, e.detail.value);
                }
                // } else {
                // that.loadHoursMinute_start(hours, minute, this.data.seatDetail.reserveTime.timeStartTime, this.data.seatDetail.reserveTime.timeEndTime - 1);
                // }
                data.multiIndex[1] = 0;

            } else {
                //明天
                // if (!this.data.seatDetail.tomorrow) {

                // 如果第一列为 '今天'并且第二列为当前时间
                if (data.multiIndex[0] === 0) {
                    that.loadData_start_tomorrow(hours, minute);
                } else {
                    console.log("loadMinute_start=== e.detail.value:", e.detail.value)
                    that.loadMinute_start(hours, minute, that.data.currNew, e.detail.value);
                }

            }

            data.multiArray[0] = hours;
            data.multiArray[1] = minute;
            this.setData(data);
        }
    },
    bindStartMultiPickerChange: function (e) {
        var that = this;
        // var monthDay = that.data.multiArray[0][e.detail.value[0]];
        var hours = that.data.multiArray[0][e.detail.value[0]];
        var minute = that.data.multiArray[1][e.detail.value[1]];

        var startDate = null;
        var minuteStr = minute;
        var hourStr = hours;
        if (minute < 10) {
            minuteStr = '0' + minute
        }
        if (hours < 10) {
            hourStr = '0' + hours
        }

        startDate = hourStr + ":" + minuteStr;
        that.setData({
            startDate: startDate,
            startTime: hours,
            startMinute: minute
        })
    },
    /**
     * 日期工具函数
     * @param {} hours 
     * @param {*} minute 
     * @param {*} startHour 
     * @param {*} endHour 
     */
    // mark: loadData_start
    loadData_start: function (hours, minute) {

        var minute_ = currentMinute;
        var maxMinute = 60;
        var index_ = 0;
        //判断当前小时在数组中的位置
        for (let index = 0; index < this.data.theResTime.length; index++) {
            const element = this.data.theResTime[index];
            if (element >= currentHours) {
                //找到当前指针的位置
                index_ = index;
                break;
            }
        }

        //第一种情况，当当前小时为结束时间，那么需要考虑多少分钟开始可以预约
        //判断其是否为预约结束
        var endMinute = this.getMinuteByResHour(this.data.theResTime[index_], false);
        if (endMinute != null) {
            //endMinute
            minute_ = parseInt(endMinute) + 10;
        }

        //第二种情况，当当前小时距离预约开始只有一个小时多的时间，那么需要考虑到最晚开始时间
        var reduce = this.getRecentReserveHour(this.data.theResTime[index_]);
        if (reduce != 10) {
            if (reduce === 1) {
                var startMinute = this.getMinuteByResHour(this.data.theResTime[index_] + parseInt(reduce), true);

                //如果当前小时超过了最晚开始时间，离下一个预约开始时间不足一个小时时
                //情况特定，第二列变成第一列，因此需要重新检查分钟
                if (currentMinute > startMinute - 10) {

                    index_++
                    //小时改变以后，需要重新考虑第一种情况是否符合
                    var endMinute = this.getMinuteByResHour(this.data.theResTime[index_], false);
                    if (endMinute != null) {
                        //endMinute
                        minute_ = parseInt(endMinute) + 10;

                    }
                } else {
                    //最晚开始应该是在预约开始的十分钟前结束
                    maxMinute = startMinute;
                }


            }
        }
        var minuteIndex;
        if (minute_ == 0) {
            minuteIndex = 0;
        } else if (minute_ > 0 && minute_ <= 10) {
            minuteIndex = 10;
        } else if (minute_ > 10 && minute_ <= 20) {
            minuteIndex = 20;
        } else if (minute_ > 20 && minute_ <= 30) {
            minuteIndex = 30;
        } else if (minute_ > 30 && minute_ <= 40) {
            minuteIndex = 40;
        } else if (minute_ > 40 && minute_ <= 50) {
            minuteIndex = 50;
        } else {
            minuteIndex = 60;
        }

        if (minuteIndex == 60) {
            //时
            for (let index = index_ + 1; index < this.data.theResTime.length; index++) {
                const element = this.data.theResTime[index];
                hours.push(element);
            }
            //分
            for (var i = 0; i < maxMinute; i += 10) {
                minute.push(i);
            }
            index_++;
        } else {
            //时
            for (let index = index_; index < this.data.theResTime.length; index++) {
                const element = this.data.theResTime[index];
                hours.push(element);
            }
            //分
            for (var i = minuteIndex; i < maxMinute; i += 10) {
                minute.push(i);
            }
        }
        return index_;
    },
    //需要根据获取到的时间来判断分钟的情况
    loadMinute_start: function (hours, minute, curIndex, indexColumn) {

        //判断该小时是否出现为两种情况之一
        //分钟默认从0开始
        var minute_ = 0;

        var maxMinute = 60;
        //分钟判断使用的索引
        var index_ = curIndex + indexColumn;

        //第一种情况，当当前小时为结束时间，那么需要考虑多少分钟开始可以预约
        //判断其是否为预约结束
        var endMinute = this.getMinuteByResHour(this.data.theResTime[index_], false);
        if (endMinute != null) {
            //endMinute
            minute_ = parseInt(endMinute) + 10;
        }
        //第二种情况，当当前小时距离预约开始只有一个小时多的时间，那么需要考虑到最晚开始时间
        var reduce = this.getRecentReserveHour(this.data.theResTime[index_]);
        if (reduce != 10) {
            if (reduce == 1) {
                var startMinute = this.getMinuteByResHour(this.data.theResTime[index_] + reduce, true);
                //如果当前小时超过了最晚开始时间，离下一个预约开始时间不足一个小时时
                // if (currentMinute > startMinute - 10) {

                //     index_++
                //     //小时改变以后，需要重新考虑第一种情况是否符合
                //     var endMinute = this.getMinuteByResHour(this.data.theResTime[index_], false);
                //     if (endMinute != null) {
                //         //endMinute
                //         minute_ = parseInt(endMinute) + 10;
                //     }
                // } else {
                //最晚开始应该是在预约开始的十分钟前结束
                // console.log("loadMinute_start=>startMinute:",this.data.theResTime[index_] )
                maxMinute = startMinute;
                // }
            }
        }

        //设置一个长度
        var minuteIndex;
        if (minute_ == 0) {
            minuteIndex = 0;
        } else if (minute_ > 0 && minute_ <= 10) {
            minuteIndex = 10;
        } else if (minute_ > 10 && minute_ <= 20) {
            minuteIndex = 20;
        } else if (minute_ > 20 && minute_ <= 30) {
            minuteIndex = 30;
        } else if (minute_ > 30 && minute_ <= 40) {
            minuteIndex = 40;
        } else if (minute_ > 40 && minute_ <= 50) {
            minuteIndex = 50;
        } else {
            minuteIndex = 60;
        }

        if (minuteIndex == 60) {

            //时
            for (let index = curIndex; index < this.data.theResTime.length; index++) {
                const element = this.data.theResTime[index];
                hours.push(element);

            }
            //分
            for (var i = 0; i < maxMinute; i += 10) {
                minute.push(i);
            }
            index_++;
        } else {
            //时
            for (let index = curIndex; index < this.data.theResTime.length; index++) {
                const element = this.data.theResTime[index];
                hours.push(element);
            }

            //分
            for (var i = minuteIndex; i < maxMinute; i += 10) {
                minute.push(i);
            }

        }
    },
    loadData_start_tomorrow: function (hours, minute) {
        var minute_ = 0;
        var maxMinute = 60;
        var index_ = 0;

        console.log("loadData_start=>this.data.theResTime[index_]:", this.data.theResTime[index_])

        //第二种情况，当当前小时距离预约开始只有一个小时多的时间，那么需要考虑到最晚开始时间
        var reduce = this.getRecentReserveHour(this.data.theResTime[index_]);
        if (reduce != 10) {
            if (reduce === 1) {
                var startMinute = this.getMinuteByResHour(this.data.theResTime[index_] + parseInt(reduce), true);

                //如果当前小时超过了最晚开始时间，离下一个预约开始时间不足一个小时时
                //情况特定，第二列变成第一列，因此需要重新检查分钟
                if (currentMinute > startMinute - 10) {
                    index_++
                    //小时改变以后，需要重新考虑第一种情况是否符合
                    var endMinute = this.getMinuteByResHour(this.data.theResTime[index_], false);
                    if (endMinute != null) {
                        //endMinute
                        minute_ = parseInt(endMinute) + 10;
                    }
                } else {
                    //最晚开始应该是在预约开始的十分钟前结束
                    maxMinute = startMinute;
                }
            }
        }

        var minuteIndex;
        if (minute_ == 0) {
            minuteIndex = 0;
        } else if (minute_ > 0 && minute_ <= 10) {
            minuteIndex = 10;
        } else if (minute_ > 10 && minute_ <= 20) {
            minuteIndex = 20;
        } else if (minute_ > 20 && minute_ <= 30) {
            minuteIndex = 30;
        } else if (minute_ > 30 && minute_ <= 40) {
            minuteIndex = 40;
        } else if (minute_ > 40 && minute_ <= 50) {
            minuteIndex = 50;
        } else {
            minuteIndex = 60;
        }

        if (minuteIndex == 60) {
            //时
            for (let index = index_ + 1; index < this.data.theResTime.length; index++) {
                const element = this.data.theResTime[index];
                hours.push(element);
            }
            //分
            for (var i = 0; i < maxMinute; i += 10) {
                minute.push(i);
            }
            index_++;
        } else {
            //时
            for (let index = index_; index < this.data.theResTime.length; index++) {
                const element = this.data.theResTime[index];
                hours.push(element);
            }
            //分
            for (var i = minuteIndex; i < maxMinute; i += 10) {
                minute.push(i);
            }
        }
        return index_;
    },


    //=========================================== // mark: loadData_end
    loadData_end: function (hours, minute, startHour, startMinute) {
        //结束时间 找出最晚结束时间根据开始时间
        //必定有一个小时的空白
        var minute_ = startMinute;
        var maxMinute = 60;
        var index_ = 0;
        var hour_max = this.data.seatDetail.reserveTime.timeEndTime;
        //判断当前小时在数组中的位置
        for (let index = 0; index < this.data.theResTime.length; index++) {
            const element = this.data.theResTime[index];
            if (element >= startHour) {
                //找到当前指针的位置
                index_ = index;
                break;
            }
        }
        console.log("loadData_end=>startHour:", startHour)

        //第一种情况，检查是否有未开始的预约，有的话设置最大小时
        var reduce = this.getRecentReserveHour(startHour);
        if (reduce != 10) {
            hour_max = startHour + reduce;
        }

        //第二种情况，检查该小时的分钟数最大值应为多少
        //如果当前小时为预约开始小时
        var resMinute = this.getMinuteByResHour(startHour)
        if (resMinute != null) {
            maxMinute = resMinute;
        }

        var minuteIndex;
        if (minute_ == 0) {
            minuteIndex = 0;
        } else if (minute_ > 0 && minute_ <= 10) {
            minuteIndex = 10;
        } else if (minute_ > 10 && minute_ <= 20) {
            minuteIndex = 20;
        } else if (minute_ > 20 && minute_ <= 30) {
            minuteIndex = 30;
        } else if (minute_ > 30 && minute_ <= 40) {
            minuteIndex = 40;
        } else if (minute_ > 40 && minute_ <= 50) {
            minuteIndex = 50;
        } else {
            minuteIndex = 60;
        }

        if (minuteIndex == 60) {
            //时
            for (let index = startHour + 1; index <= hour_max; index++) {
                hours.push(index);
            }
            //分
            for (var i = 0; i < maxMinute; i += 10) {
                minute.push(i);
            }
            index_++;
        } else {
            //时
            for (let index = startHour; index <= hour_max; index++) {
                hours.push(index);
            }
            //分
            for (var i = minuteIndex; i < maxMinute; i += 10) {
                minute.push(i);
            }
        }
    },

    loadMinute_end: function (hours, minute, startTime, indexColumn) {
        var minute_ = 0;
        var maxMinute = 60;
        var index_cur = startTime + indexColumn;
        var hour_max = this.data.seatDetail.reserveTime.timeEndTime;



        //第一种情况，检查是否有未开始的预约，有的话设置最大小时
        var reduce = this.getRecentReserveHour(index_cur);

        if (reduce != 10) {
            hour_max = index_cur + parseInt(reduce);
        }
        console.log("loadMinute_end=>index_cur:", index_cur)

        //第二种情况，检查该小时的分钟数最大值应为多少
        //如果当前小时为预约开始小时
        var resMinute = this.getMinuteByResHour(index_cur, true)
        if (resMinute != null) {
            maxMinute = resMinute;
        }
        console.log("loadMinute_end=>maxMinute:", maxMinute)
        var minuteIndex;
        if (minute_ == 0) {
            minuteIndex = 0;
        } else if (minute_ > 0 && minute_ <= 10) {
            minuteIndex = 10;
        } else if (minute_ > 10 && minute_ <= 20) {
            minuteIndex = 20;
        } else if (minute_ > 20 && minute_ <= 30) {
            minuteIndex = 30;
        } else if (minute_ > 30 && minute_ <= 40) {
            minuteIndex = 40;
        } else if (minute_ > 40 && minute_ <= 50) {
            minuteIndex = 50;
        } else {
            minuteIndex = 60;
        }

        if (minuteIndex == 60) {

            //时
            for (let index = startTime + 1; index < hour_max; index++) {
                hours.push(index);
            }
        } else {
            //时
            for (let index = startTime; index <= hour_max; index++) {
                hours.push(index);
            }
        }
        //分
        for (var i = 0; i < maxMinute; i += 10) {
            minute.push(i);

        }


    },

    //=========================================
    convertMonthDay: function (month, day) {
        var monthStr;
        var dayStr;
        if (month < 10) {
            monthStr = '0' + month
        } else {
            monthStr = month
        }
        if (day < 10) {
            dayStr = '0' + day;
        } else {
            dayStr = day
        }
        return monthStr + '月' + dayStr + '日'
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var that = this
        var detail = JSON.parse(options.detail)

        console.log("currentHours", currentHours)
        this.setData({
            seatDetail: detail,
            currentHour_: currentHours

        })
        console.log(this.data.seatDetail)

        //获取最新的可预约时间
        //可预约时间设置规则：
        /**
         * 当前时间为12 
         * 15-12=3 3>1=>可将开始预约时间修改至当前时间
         * 假设预约时间为15-18
         * 
         * 14-15、16-17
         * 思路：
         * 1、生成时间数组
         */
        var theResTime = [];
        var theResMinute = [];
        for (var i = detail.reserveTime.timeStartTime; i < detail.reserveTime.timeEndTime - 1; i++) {
            theResMinute.push(60);
            theResTime.push(i);
        }

        // //除预约一天的
        // //找出结束时间，如果结束时间不等于可预约结束时间
        // //找出开始时间与theResTime中对应的数字，设置其为0
        if (this.data.seatDetail.resTime != null) {

            theResTime = this.getTheResTime_(theResTime)
            //将不可预约的开始时间都已设置为0，删除为0的值
            var temp = theResTime;
            var theResTime1 = [];
            for (let index = 0; index < temp.length; index++) {
                const element = temp[index];
                if (element != 0) {
                    theResTime1.push(element);
                }
            }
            console.log("theResTime1:", theResTime1)
            //如果当前时间已经大于预约时间数组theResTime1的最后一项，说明今日预约已结束
            if (currentHours > theResTime1[theResTime1.length - 1]) {
                if (!detail.tomorrow) {
                    that.setData({
                        todayReserve_over: true
                    })
                }
            }

            this.setData({
                theResTime: theResTime1,

            })
            //小时数组调节完成
            /**
             * 调节分钟数组 // mark: 分钟调节开始
             */
            // this.adjustTheResMinute(theResTime1);
        } else {
            this.setData({
                theResTime: theResTime,
            })

        }

        // console.log(start)
        // console.log(that.data.resEndHour)
        this.setData({
            reserve: getApp().user_reserve,

        })
        console.log("onLoad=> getApp().user_reserve:", getApp().user_reserve,)

    },
    //通过小时找到相应预约时间
    getMinuteByResHour: function (ResHour, check) {
        var list = this.data.seatDetail.resTime;
        var res = null;
        // console.log(list)
        if (list != null) {
            list.forEach(element => {
                var startNums = element.resStartTime.split(':');
                var endNums = element.resEndTime.split(':');
                //check:true 开始时间,false:结束时间
                if (check) {
                    if (parseInt(startNums[0]) == ResHour) {
                        res = startNums[1]
                    }
                } else {
                    if (parseInt(endNums[0]) == ResHour) {
                        res = endNums[1]
                    }
                }

            });
        }
        return res;

    },
    // 获取将来时间中,最近的开始时间差值
    getRecentReserveHour: function (startTime) {
        var list = this.data.seatDetail.resTime
        var min = 10;
        if (list != null) {
            list.forEach(element => {
                var startNums = element.resStartTime.split(':');
                var endNums = element.resEndTime.split(':');
                if (parseInt(startNums[0]) - startTime >= 0) {
                    if (min > parseInt(startNums[0]) - startTime) {
                        min = parseInt(startNums[0]) - startTime
                    }
                }
            })
        }

        return min;
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {


    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },

    // ==========================================================
    getTheResTime_: function (theResTime) {
        var list = this.data.seatDetail.resTime;
        for (let index = 0; index < list.length; index++) {
            const element = list[index];

            var startNums = element.resStartTime.split(':');
            var endNums = element.resEndTime.split(':');

            //如果可预约时间与预约开始时间相距不足一小时
            if (parseInt(startNums[0]) - this.data.seatDetail.reserveTime.timeStartTime < 1 || this.data.seatDetail.reserveTime.timeStartTime - parseInt(startNums[0]) == 1) {

                //可预约开始时间与预约开始时间相差不足一个小时，则将数组设0至结束时间
                if (this.data.seatDetail.reserveTime.timeEndTime - parseInt(endNums[0]) > 1) {
                    //说明今天预约已经满了，设置一个预约已满的标志
                    break;
                } else {
                    for (var j = 0; j < theResTime.length; j++) {
                        if (theResTime[j] < endNums[0]) {
                            theResTime[j] = 0;
                        }
                        continue;
                    }
                }
            }

            theResTime = this.judgeTheResTime1(theResTime, startNums[0], endNums[0])
            theResTime = this.judgeTheResTime2(theResTime, startNums[0])
            theResTime = this.judgeTheResTime3(theResTime, endNums[0])
        }
        return theResTime;

    },

    // mark: 预约时间规则
    judgeTheResTime1: function (theResTime, startHour, endHour) {
        // 先将预约时间段中间设为0
        for (var e = 0; e < theResTime.length; e++) {
            if (theResTime[e] > parseInt(startHour) && theResTime[e] < parseInt(endHour) && theResTime[e] != 0) {
                theResTime[e] = 0
            }
        }
        return theResTime
    },
    judgeTheResTime2: function (theResTime, startHour) {
        console.log("judgeTheResTime2=>theResTime_before::", theResTime)

        // 预约开始时间与开始时间前的一个小时问题
        var startMin = this.getMinuteByResHour(startHour, true)
        var deleteHour = -1
        if (parseInt(startMin) < 10) {
            deleteHour = parseInt(startHour) - 1
            console.log("judgeTheResTime2=>startMin::", startMin)
        }
        for (var e = 0; e < theResTime.length; e++) {
            if (deleteHour == -1) {
                if (theResTime[e] == startHour) {
                    theResTime[e] = 0
                    break;
                }
            } else {
                if (theResTime[e] == deleteHour) {
                    theResTime[e] = 0
                    theResTime[e + 1] = 0
                    break;
                }
            }
        }
        console.log("judgeTheResTime2=>theResTime_after::", theResTime)

        return theResTime;
    },

    judgeTheResTime3: function (theResTime, endHour) {
        // 结束时间与下一个开始时间之间的问题
        var min = this.getRecentReserveHour(endHour);
        var deleteHour = -1;
        var special = false;
        if (min != 10) {
            //说明存在下一个开始时间
            if (min === 1) {
                var minu1 = this.getMinuteByResHour(parseInt(endHour) + 1, false);
                var minu2 = this.getMinuteByResHour(parseInt(endHour), false);
                if (minu2 - minu1 < 10) {
                    deleteHour = parseInt(endHour) + 1
                }
            }
        }

        console.log("judgeTheResTime3=>endHour:", endHour)
        //如果当前小时就是预约结束小时
        //判断，如果分钟数为50则要删除该小时
        if (parseInt(this.getMinuteByResHour(parseInt(endHour), false)) == 50) {
            deleteHour = parseInt(endHour)
            special = true;
        }

        for (var e = 0; e < theResTime.length; e++) {
            if (deleteHour > 0 && !special) {
                if (theResTime[e] == deleteHour) {
                    theResTime[e] = 0
                    theResTime[e - 1] = 0
                    break;
                }
            }
            if (deleteHour > 0 && special) {
                if (theResTime[e] == deleteHour) {
                    theResTime[e] = 0
                    break;
                }
            }

        }
        return theResTime;
    },

    deleteFromArray: function (array, index_) {
        var arrayNew = [];

        array.forEach(element => {
            if (array[index_] !== element) {
                arrayNew.push(element)
            }
        });


        console.log("deleteFromArray=>arrayNew:", arrayNew)
        return arrayNew

    }
    // //=================================
    // adjustTheResMinute(theResTime){
    //     var temp=theResTime[0];
    //     for (let index = 1; index < theResTime.length; index++) {
    //         const element = array[index];

    //         if (temp+1 !== element) {
    //             //有差额，就说明与上一个
    //         }


    //     }
    // }
})